/**
 * 
 */
package com.music.profile.controller;

import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.music.core.members.beans.Member;
import com.music.core.members.service.MemberService;


/**
 * @author spradeep
 *
 */
public class CreateMemberController extends AbstractController {
	private static final Logger log = Logger.getLogger(CreateMemberController.class.getName());

	private MemberService memberService;
	
	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		
		Map parameterMap = req.getParameterMap();
		Set keySet = parameterMap.keySet();
		for (Object object : keySet) {
			String key = (String)object;
			System.out.println(key+"="+req.getParameter(key));
		}
		
		
		String dateParam = req.getParameter("datepicker");
		String firstName = req.getParameter("firstname");
		String lastName = req.getParameter("lastname");
		String password = req.getParameter("password");
		String gender = req.getParameter("gender");
		String email = req.getParameter("email");
		
		// TODO: No duplicate email ids.
		
		Member member  = memberService.createMember(firstName, lastName, password, dateParam, gender, email);
		System.out.println("Member Registered Successfully with member id=" + member.getMemberId());
		return new ModelAndView("registrationSuccess");
	}

}
